import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';
import 'package:validatorless/validatorless.dart';
import 'package:zz_listen_english/common/index.dart';


import 'index.dart';

class LoginPage extends GetView<LoginController> {
  const LoginPage({Key? key}) : super(key: key);
  Widget _buildFrom() {
    return Form(
        key: controller.fromKeyId,
        autovalidateMode: AutovalidateMode.onUserInteraction,
        child: <Widget>[
          //用户名
          TextFormWidget(
              autofocus: true,
              controller: controller.userNameController,
              labelText: '账号:',
              validator: Validatorless.multiple([
                Validatorless.required("不能为空！"),
              ])).paddingBottom(20),

          //密码
          TextFormWidget(
              controller: controller.passwordController,
              labelText: '密码',
              isObscure: true,
              validator: Validatorless.multiple([
                Validatorless.required("不能为空！"),
              ])).paddingBottom(20),
          //登录按钮
           ElevatedButton(child:Text('登录'), onPressed: controller.onSignIn)
               .paddingBottom(30.w),
        ].toColumn().paddingAll(20));
  }

  /// 设置ip 跳转页面
  _buildIp() {
    return Container(
      child: <Widget>[
        IconButton(icon:
          const Icon(Icons.settings),
          onPressed: () => controller.onSetIp(),

        ),
      ]
          .toRow(mainAxisAlignment: MainAxisAlignment.end)
          .marginOnly(bottom: 200, top: 10),
    );
  }

  // 主视图
  Widget _buildView() {
    return Container(
        child: <Widget>[
      /// 设置ip
      _buildIp(),

      ///表单
      _buildFrom().card(color: Colors.white)
    ].toColumn(mainAxisAlignment: MainAxisAlignment.start).marginAll(20));
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<LoginController>(
      init: LoginController(),
      id: "login",
      builder: (_) {
        return Scaffold(
          resizeToAvoidBottomInset: false,
          body: _buildView(),
        );
      },
    );
  }
}
